<template>
  <div>
    <div class="item">
      <div>todos.done为true的数据: {{ $store.getters.doneTodos }}</div>
      <div>todos.done为true的数据长度: {{ doneTodosCount }}</div>
      <div>todos.id=2的数据: {{ doneTodo }}</div>
      <div>mapGetters.doneCount: {{ doneCount }}</div>
    </div>
  </div>
</template>


<script>
import { mapState, mapGetters } from "vuex";
import CuGetter from "./getter.vue";
export default {
  components: {
    "cu-getter": CuGetter
  },
  name: "Getter",
  data() {
    return {
      doneTodo: {}
    };
  },
  computed: {
    doneTodosCount() {
      return this.$store.getters.doneTodosCount;
    },
    ...mapGetters({
      // 把 `this.doneCount` 映射为 `this.$store.getters.doneTodosCount`
      doneCount: "doneTodosCount"
    })
  },
  methods: {
    incement() {
      this.$store.commit("increment");
    }
  },
  created() {
    this.doneTodo = this.$store.getters.getTodoById(2);
    // console.log((this.doneTodo = this.$store.getters.getTodoById(2)));
  }
};
</script>


<style lang="less" scope>
.item {
  width: 100%;
  // height: ;
  border-bottom: 1px solid #ddd;
  padding: 10px 30px;
  .btn {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 8px;
    line-height: 30px;
    text-align: center;
    border: 1px solid #ddd;
    margin-top: 10px;
  }
}
</style>